import allure
from selenium.webdriver.common.by import By

from page.base_page import BasePage
from page.main_page import MainPage


class LoginPage(BasePage):
    __USERNAME_BUTTON = By.XPATH, "//*[@placeholder = '账号']"
    __PASSWORD_BUTTON = By.XPATH, "//*[@placeholder = '密码']"
    __SUBMIT_BUTTON = By.XPATH, "//*[@class  = 'el-button el-button--primary el-button--large']"

    def login(self, username, password):
        with allure.step(f"输入用户名{username}"):
            self.find_and_send(*self.__USERNAME_BUTTON, text=username)
        with allure.step(f"输入密码{password}"):
            self.find_and_send(*self.__PASSWORD_BUTTON, text=password)
        with allure.step("点击登录"):
            self.find_and_click(*self.__SUBMIT_BUTTON)
        return MainPage(self.driver)
